package session

import (
	_ "github.com/astaxie/beego/session/mysql"
	"github.com/astaxie/beego/session"
	"github.com/astaxie/beego"
	"fmt"
)

var globalSessions *session.Manager
func init() {
	/*sessionConfig:=`{"cookieName":"xgggh_sessionid",
	 "enableSetCookie,omitempty": true, "gclifetime":3600, "maxLifetime": 3600, "secure": false,
	 "sessionIDHashFunc": "sha1",
	 "sessionIDHashKey": "", "cookieLifeTime": 3600, "providerConfig": ""}`*/
	user := beego.AppConfig.String("mysql.user")
	pass := beego.AppConfig.String("mysql.pass")
	host := beego.AppConfig.String("mysql.host")
	port,_:= beego.AppConfig.Int64("mysql.port")
	db := beego.AppConfig.String("mysql.db")
	args := fmt.Sprintf(
		"%s:%s@tcp(%s:%d)/%s?charset=utf8&loc=UTC",
		user,
		pass,
		host,
		port,
		db,
	)
	sessionConfiger:=session.ManagerConfig{CookieName:"xgggh_sessionid",
		EnableSetCookie:true,
		Gclifetime:3600,
		Maxlifetime:3600,
		Secure:false,
		CookieLifeTime:3600,
		ProviderConfig:args,}

	globalSessions, _ = session.NewManager("mysql",&sessionConfiger)
	go globalSessions.GC()
}
